#include <QColor>
#include <QStringList>
#include <QVariant>
#include <QDataStream>


enum PHASE{REINFORCEMENT, ATTACK, MOVE, BATTLE};
enum REQUEST{PHASE_CHANGED, PLAYER_INFOS, STATE_INFOS, ALL_STATES_INFOS, ALL_PLAYERS_INFOS, ERROR, INFOS, REQUEST_DICE_ROLL, PLAYER_DEFEATED, GAME_STARTED, LOBBY_STATE_CHANGED,   /// Server ///
             REQUEST_NEXT_PHASE, REQUEST_PLAYER_INFOS, REQUEST_STATE_INFOS, REQUEST_MOVEMENT, REQUEST_ATTACK, REQUEST_REINFORCEMENT, REQUEST_UPDATE, REQUEST_LOBBY_STATE_CHANGE}; /// Client ///

enum ERROR_CODE{UNKNOWN_ERROR, NOT_YOUR_TURN, NOT_ENOUGHT_TROOPS, NOT_YOUR_STATE, STATE_DOES_NOT_EXIST, PLAYER_DOES_NOT_EXIST, GAME_NOT_STARTED_YET};
enum INFOS_CODE{TROOPS_MOVEMENT, BATTLE_BEGIN, REINFORCEMENTS, DICE_ROLLED, ATTACKER_WINS, DEFENSOR_WINS, BONUS_USED};

double time();

struct Data
{
    Data() { timeout = 0; canTimeout = false;}
    void setTimeOut (double s) { timeout = time() + s; canTimeout = true;}
    bool isTooLate() const { return (time() > timeout) && canTimeout; }
    bool canTimeout;
    double timeout;
    QByteArray data;
};

struct PlayerInfos
{
    PlayerInfos ()
    {
        static bool first = true; if(first) { qRegisterMetaTypeStreamOperators<PlayerInfos>("PlayerInfos"); qMetaTypeId<PlayerInfos>(); first = false; }
        ID = 0; reinforcements = 0; KIA = false;
    }

    quint16 ID;
    QColor color;
    QStringList ownedStates;

    quint16 reinforcements;
    bool KIA;

};
Q_DECLARE_METATYPE(PlayerInfos)
QDataStream & operator << (QDataStream & out, const PlayerInfos& p);
QDataStream & operator >> (QDataStream & in, PlayerInfos& p);


struct StateInfos
{
    StateInfos ()
    {
        static bool first = true; if(first) { qRegisterMetaTypeStreamOperators<StateInfos>("StateInfos"); qMetaTypeId<StateInfos>(); first = false; }
        ID = 0; ownerID = 0;
    }
    QString name;
    quint16 ID;
    quint16 ownerID;
    QStringList connexions;
};
Q_DECLARE_METATYPE(StateInfos)
QDataStream & operator << (QDataStream & out, const StateInfos& p);
QDataStream & operator >> (QDataStream & in, StateInfos& p);
